<?php

namespace App\Controller\Api;

use App\Base\BaseController4Api;
use App\Entity\ApiMoney;
use App\Entity\ApiUser;
use App\Model\ApiMoneyConfigModel;
use App\Model\ApiMoneyLogModel;
use App\Model\ApiMoneyModel;
use App\Model\ApiMoneyTypeModel;
use App\Model\ApiUserModel;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;

use Symfony\Component\HttpFoundation\Request;


/**
 * @route("/api")
 */
class ApiMoneyConfigController extends BaseController4Api
{

    /**
     * @route("/get_money_config",name="ApiMoneyConfigGet")
     */
    public function ApiMoneyConfigGet()
    {
        $projectId = $this->getProjectId();
        $ApiMoneyConfigModel = new ApiMoneyConfigModel($this->getDoctrine());
        $data = $ApiMoneyConfigModel->getArrayByKV("project_Id",$projectId);
        return $this->json_out(1,"数据获取成功",$data);
    }


    /**
     * @route("/set_money_config",name="ApiMoneyConfigSet")
     */
    public function ApiMoneyConfigSet()
    {
        $projectId = $this->getProjectId();
        if (!$id = $this->getParamRequired("id")) {return $this->json_out(0,"请设置ID");}
        if (!$val = $this->getParamRequired("val")) {
            if ($val === "" || $val === 0 || $val === "0") {
            }else{
                return $this->json_out(0,"请设置值");
            }
        }
        if (!$tips = $this->getParamRequired("tips")) {$tips = "";}

        $ApiMoneyConfigModel = new ApiMoneyConfigModel($this->getDoctrine());
        $config = $ApiMoneyConfigModel->getByKV("id",$id);
        if (!$config || $config->getProjectId() != $projectId) {
            die("access denied");
        }
        $config->setV($val)
            ->setTips($tips);
        $this->myEm()->persist($config);$this->myEm()->flush();
        return $this->json_out(1,"设置成功");
    }

}
